<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <base href="${pageContext.request.contextPath}/">
    <title>Title</title>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- bootstrap-table样式文件 -->
    <link rel="stylesheet" href="bootstrap-table/bootstrap-table.min.css">
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
    <!-- bootstrap-table的js文件 -->
    <script type="text/javascript" src="bootstrap-table/bootstrap-table.min.js"></script>
    <!-- bootstrap-table的语言包 -->
    <script type="text/javascript" src="bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
    <script type="text/javascript">
        $(function () {
            initTable();

            $("#in_orgId").change(function () {
                 // alert($("#in_orgId option:selected").text()+"---"+$("#in_orgId").val()+"---"+$("#in_orgId option:selected").attr("code"));
            });
        });
        //初始化表格
        function initTable() {
            $("#tab").bootstrapTable({
                //表格高度
                height: 560,
                // theadClasses: ".thead-dark",
                //本地的数据
                // data:[
                //     {"id":1001,"name":"tom","gender":"0"},
                //     {"id":1002,"name":"jerry","gender":"1"},
                //     {"id":1003,"name":"zhangsan","gender":"0"},
                //     {"id":1004,"name":"lisi","gender":"1"}
                // ],
                //远程访问地址
                url: "leader/list",
                //请求方法
                method: "get",
                //异步提交时向后台提交的请求参数
                queryParams: function(params){
                    params["leaderName"]=$("#leaderName").val().trim();
                    return params;
                 },
                //修改分页组件向后台提交数据
                queryParamsType: "",
                //开启分页
                pagination: true,
                //设置服务器分页
                sidePagination: "server",
                //每页条数
                pageSize: 10,
                //用户设置的每页条数列表
                pageList: [10,20,30,50],
                //上一页和下一页文本
                paginationPreText: "上一页",
                paginationNextText: "下一页",
                //刷新按钮
                showRefresh: true,
                //点击选中
                clickToSelect: true,
                //单选
                singleSelect: false,
                //工具栏
                toolbar: "#toolbar",
                //表格中的列描述
                columns: [
                    {
                        //表格第一列为复选框
                        checkbox: true
                    },{
                        //表示json字符串中的属性名称
                        /*
                            "[{"id":1001,"name":"tom","gender":"0"},{"id":1002,"name":"jerry","gender":"1"}]"
                         */
                        field: "id",
                        //隐藏列
                        visible: false
                    },{
                        //表头中的文本
                        field: "orgId",
                        //设置表头的对齐方式
                        title: "机构id",
                        halign: "center"
                    },{
                        field: "orgName",
                        title: "机构名称",
                        halign: "center"
                    },{
                        field: "orgNo",
                        title: "内部编码",
                        halign: "center"
                    },{
                        field: "orgCode",
                        title: "机构代码",
                        halign: "center",
                    },{
                        field: "formFillingMan",
                        title: "填表人",
                        halign: "center",
                    },{
                        field: "linkTel",
                        title: "联系电话",
                        halign: "center",
                        // formatter: function (value) {
                        //     var ifSub = ["是","否"];
                        //     return ifSub[value];
                        // }
                    },{
                        field: "leaderName",
                        title: "领导姓名",
                        halign: "center"
                    },{
                        field: "gender",
                        title: "性别",
                        halign: "center",

                    },{
                        field: "folk",
                        title: "民族",
                        halign: "center"
                    },{
                        field: "pol",
                        title: "政治面貌",
                        halign: "center"
                    },{
                        field: "edu",
                        title: "学历",
                        halign: "center"
                    },{
                        field: "degree",
                        title: "学位",
                        halign: "center"
                    },{
                        field: "manageJob",
                        title: "职务",
                        halign: "center"
                    },{
                        field: "title",
                        title: "职称",
                        halign: "center"
                    },{
                        field: "memo",
                        title: "备注",
                        halign: "center"
                    },{
                        field: "serDate",
                        title: "任职日期",
                        halign: "center"
                    },{
                        field: "leaveDate",
                        title: "离职日期",
                        halign: "center"
                    },{
                        field: "yearly",
                        title: "年份",
                        halign: "center"
                    }
                ]
            });
        }

        function insert() {
            $.post("organization/list",null,function (res) {
                var str = "<option value=''>--请选择--</option>";
                var org;
                $.each(res.rows,function () {
                    str += "<option value='" +this.id+"' name='" +this.orgname+"' no='"+this.orgNo+"' code='"+this.orgCode+"'>"+ this.orgname + "</option>";
                });
                console.log(res);
                $("#in_orgId").html(str);
                $("#insert_win").modal("show");
            })
        }
        function doInsert(){
            $.post("leader/add",{
                id:$("#in_id").val().trim(),
                orgId : $("#in_orgId").val().trim(),
                orgName : $("#in_orgId option:selected").attr("name"),
                orgNo : $("#in_orgId option:selected").attr("no"),
                orgCode : $("#in_orgId option:selected").attr("code"),
                formFillingMan : $("#in_formFillingMan").val(),
                linkTel : $("#in_linkTel").val().trim(),
                leaderName : $("#in_leaderName").val().trim(),
                gender : $("#in_gender").val().trim(),
                folk : $("#in_folk").val().trim(),
                birthDate : $("#in_birthDate").val().trim(),
                pol : $("#in_pol").val().trim(),
                edu : $("#in_edu").val().trim(),
                degree : $("#in_degree").val().trim(),
                manageJob : $("#in_manageJob").val().trim(),
                title : $("#in_title").val().trim(),
                memo : $("#in_memo").val().trim(),
                serDate : $("#in_serDate").val().trim(),
                leaveDate : $("#in_leaveDate").val().trim(),
                yearly : $("#in_yearly").val().trim()
            },function (res) {
                if(res.status==200){
                    alert("新增成功");
                    $("#insert_win").modal("hide");
                    $("#tab").bootstrapTable("refresh");
                    $("#insert_form")[0].reset();
                }
            });
        }

        function doPreUpdate() {
            var rows = $("#tab").bootstrapTable("getSelections");
            if(rows.length==0){
                alert("请选中一条要修改的数据");
            }else if(rows.length>1){
                alert("只能修改一条数据");
            }else{
                $.get("leader/listOrg",{},function (res) {
                    var html="<option value='0'>--请选择--</option>";
                    $.each(res.data,function () {
                        html +="<option value="+this.id+">"+this.orgname+"</option>"
                    })
                    $("#up_orgname").html(html);
                    $.get("leader/get/"+rows[0].id,null,function (res) {
                        $("#up_id").val(res.data.id);
                        $("#up_orgId").val(res.data.orgId);
                        $("#up_orgname").val(res.data.orgId);
                        $("#up_orgNo").val(res.data.orgNo);
                        $("#up_orgCode").val(res.data.orgCode);
                        $("#up_formFillingMan").val(res.data.formFillingMan);
                        $("#up_linkTel").val(res.data.linkTel);
                        $("#up_leaderName").val(res.data.leaderName);
                        $("#up_gender").val(res.data.gender);
                        $("#up_folk").val(res.data.folk);
                        $("#up_birthDate").val(res.data.birthDate);
                        $("#up_pol").val(res.data.pol);
                        $("#up_edu").val(res.data.edu);
                        $("#up_degree").val(res.data.degree);
                        $("#up_manageJob").val(res.data.manageJob);
                        $("#up_title").val(res.data.title);
                        $("#up_memo").val(res.data.memo);
                        $("#up_serDate").val(res.data.serDate);
                        $("#up_leaveDate").val(res.data.leaveDate);
                        $("#up_yearly").val(res.data.yearly);
                        });
                        $("#update_win").modal("show");
                    })
                }
            }

        function doUpdate(){
            $.post("leader/update",{
                id : $("#up_id").val(),
                orgId  : $("#up_orgId ").val().trim(),
                orgName : $("#up_orgname option:selected").text(),
                orgNo : $("#up_orgNo").val().trim(),
                orgCode : $("#up_orgCode").val().trim(),
                formFillingMan : $("#up_formFillingMan").val().trim(),
                linkTel : $("#up_linkTel").val().trim(),
                leaderName : $("#up_leaderName").val().trim(),
                gender : $("#up_gender").val().trim(),
                folk : $("#up_folk").val().trim(),
                birthDate : $("#up_birthDate").val(),
                pol : $("#up_pol").val().trim(),
                edu : $("#up_edu").val().trim(),
                degree : $("#up_degree").val().trim(),
                manageJob : $("#up_manageJob").val().trim(),
                title : $("#up_title").val().trim(),
                memo : $("#up_memo").val().trim(),
                serDate : $("#up_serDate").val(),
                leaveDate : $("#up_leaveDate").val(),
                yearly : $("#up_yearly").val().trim(),
            },function (res) {
                if(res.status==200){
                    alert("修改成功");
                    $("#update_win").modal("hide");
                    $("#tab").bootstrapTable("refresh");
                    $("#update_form")[0].reset();
                }
            });
        }

        function doDelete() {
            var rows = $("#tab").bootstrapTable("getSelections");
            if(rows.length==0){
                alert("请选中一条要删除的数据");
            }else{
                if(!confirm("确定删除吗?")) return;
                var ids = [];
                $.each(rows, function () {
                    ids.push(this.id);
                });
                // alert(ids);
                $.get("section/removeBatch",{ids : ids},function (res) {
                    if(res.status==200){
                        alert("删除成功");
                        $("#tab").bootstrapTable("refresh");
                    }
                });
            }
        }

    </script>
</head>
<body>
    <!--=======================路径导航=========================-->
    <ol class="breadcrumb">
        <li>主页</li>
        <li>系统管理</li>
        <li class="active">组织机构</li>
    </ol>
    <!--=======================路径导航.end=========================-->
    <!--=======================页面主体=========================-->
    <div class="panel-body">
        <form id="toolbar" class="form-inline">
            <div class="btn-group">
                <button type="button" class="btn btn-default" onclick="insert()">新增</button>
                <button type="button" class="btn btn-success" onclick="doPreUpdate()">修改</button>
                <button type="button" class="btn btn-danger" onclick="doDelete()">删除</button>
            </div>
            <div class="form-group">
                <input type="text" class="form-control" id="leaderName" placeholder="领导姓名">
            </div>
            <div class="form-group">
                <select id="status" class="form-control">
                    <option value="">--用户状态--</option>
                    <option value="0">正常</option>
                    <option value="1">停用</option>
                </select>
            </div>
            <div class="btn-group">
                <button type="button" class="btn btn-default" onclick="$('#tab').bootstrapTable('refresh')">搜索</button>
                <button type="button" class="btn btn-default" onclick="$('#toolbar')[0].reset();$('#tab').bootstrapTable('refresh');">清空</button>
            </div>
        </form>
        <table id="tab" class="table table-bordered table-hover table-striped"></table>
    </div>
    <!--=======================页面主体.end=========================-->
    <!--=======================新增窗体=========================-->
    <div id="insert_win" class="modal fade"  tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document" style="width: 350px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">新增领导</h4>
                </div>
                <div class="modal-body">
                    <form id="insert_form">
                        <input type="hidden" id="in_id" >
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">机构名称</div>
                                <select type="text" id="in_orgId" class="form-control" >
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">填表人</div>
                                <input type="text" id="in_formFillingMan" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">联系电话</div>
                                <input type="text" id="in_linkTel" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">领导姓名</div>
                                <input type="text" id="in_leaderName" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">性别</div>
                                <input type="text" id="in_gender" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">民族</div>
                                <input type="text" id="in_folk" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">出生年月</div>
                                <input type="date" id="in_birthDate" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">政治面貌</div>
                                <input type="text" id="in_pol" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">学历</div>
                                <input type="text" id="in_edu" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">学位</div>
                                <input type="text" id="in_degree" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">职务</div>
                                <input type="text" id="in_manageJob" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">职称</div>
                                <input type="text" id="in_title" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">备注</div>
                                <input type="text" id="in_memo" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">任职日期</div>
                                <input type="date" id="in_serDate" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">离职日期</div>
                                <input type="date" id="in_leaveDate" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">年份</div>
                                <input type="text" id="in_yearly" class="form-control">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" onclick="doInsert()">确定</button>
                </div>
            </div>
        </div>
    </div>
    <!--=======================新增窗体.end=========================-->
    <!--=======================修改窗体=========================-->
    <div id="update_win" class="modal fade" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">修改领导信息</h4>
                </div>
                <div class="modal-body">
                    <form id="update_form">
                        <input type="hidden" id="up_id">
                        <%--<input type="hidden" id="up_updater" value="lisi">--%>
                        <input type="hidden" id="up_orgId" >
                        <input type="hidden" id="up_orgNo" >
                        <input type="hidden" id="up_orgCode" >
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">机构名称</div>
                                <%--<input type="text" id="up_orgname" class="form-control" >--%>
                                <select id="up_orgname" class="form-control">
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">填表人</div>
                                <input type="text" id="up_formFillingMan" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">联系电话</div>
                                <input type="text" id="up_linkTel" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">领导姓名</div>
                                <input type="text" id="up_leaderName" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">性别</div>
                                <input type="text" id="up_gender" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">民族</div>
                                <input type="text" id="up_folk" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">出生年月</div>
                                <input type="date" id="up_birthDate" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">政治面貌</div>
                                <input type="text" id="up_pol" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">学历</div>
                                <input type="text" id="up_edu" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">学位</div>
                                <input type="text" id="up_degree" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">职务</div>
                                <input type="text" id="up_manageJob" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">职称</div>
                                <input type="text" id="up_title" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">备注</div>
                                <input type="text" id="up_memo" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">任职日期</div>
                                <input type="date" id="up_serDate" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">离职日期</div>
                                <input type="date" id="up_leaveDate" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">年份</div>
                                <input type="text" id="up_yearly" class="form-control">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" onclick="doUpdate()">确定</button>
                </div>
            </div>
        </div>
    </div>
    <!--=======================修改窗体.end=========================-->
</body>
</html>
